package com.qaml.mes.device.domain.service;

import com.qaml.mes.device.api.EqpAttachmentService;
import com.qaml.mes.device.dao.EqpAttachmentDO;
import com.qaml.mes.device.repository.EqpAttachmentRepository;
import com.qaml.mes.device.domain.convert.EqpAttachmentConvert;
import com.qaml.mes.device.vo.eqp.EqpAttachmentVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 设备附件表 服务实现类
 * </p>
 *
 * @author leikai
 * @since 2024-02-27
 */
@Service
public class EqpAttachmentServiceImpl implements EqpAttachmentService {

    @Resource
    EqpAttachmentRepository eqpAttachmentRepository;

    /**
     * 根据设备id删除设备附件  --逻辑删除
     *
     * @param eqpId
     */
    @Override
    public void deleteByEqpId(String eqpId) {

        // 1,获取设备附件信息
        List<EqpAttachmentDO> eqpAttachmentDOList = eqpAttachmentRepository.getByEqpId(eqpId);
        // 2,删除设备附件
        // 获取所有附件的id
        List<String> ids = eqpAttachmentDOList.stream().map(EqpAttachmentDO::getId).collect(Collectors.toList());
        // 批量删除
        // 批量修改，设置isDeleted=1(在Mapper中完成)
        eqpAttachmentRepository.updateEqpAttachmentByIds(ids);
    }

    /**
     * 获取设备附件以及设备图片信息   -- 根据类型以及设备id
     *
     * @param id
     * @param type
     * @return
     */
    @Override
    public List<EqpAttachmentVO> getEqpAttachmentList(String id, String type) {

        List<EqpAttachmentDO> eqpAttachmentDOList = eqpAttachmentRepository.getByEqpIdAndStatus(id, type);
        return EqpAttachmentConvert.INSTANCE.toVOList(eqpAttachmentDOList);
    }


}
